package com.vteApp.dal;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class RiskDBAdapter {
	public final static String TABLE_NAME = "risk";
	public final static String KEY_ID = "_id";
	public final static String KEY_FACTOR = "factor";
	public final static String KEY_TITLE = "title";
	public final static String KEY_REQUIRED = "required";
	public final static String KEY_VALUE = "value";
	Context context;
	RiskDBHelper helper;
	private SQLiteDatabase db;

	public RiskDBAdapter(Context context) {
		super();
		this.context = context;
	}

	public RiskDBAdapter open() {
		helper = new RiskDBHelper(context);
		db = helper.getWritableDatabase();
		return this;
	}

	public Cursor fetchAllRisks() {
		return db.query(TABLE_NAME, new String[] { KEY_ID, KEY_FACTOR,
				KEY_TITLE, KEY_REQUIRED, KEY_VALUE }, null, null, null, null,
				KEY_ID);
	}

	public long updateRisk(long id, boolean value) {
		ContentValues values = new ContentValues();
		values.put(KEY_VALUE, value);
		return db.update(TABLE_NAME, values, KEY_ID + "=" + id, null);
	}
}
